﻿package com.game.view.layer.gameMap
{
	import AssetClass.*;
	
	import com.game.event.GameEvent;
	import com.game.manager.NotificationManager;
	
	import config.Config;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ParadiseMap extends GameMapBase implements IGameMap
	{
		
		private const MAP_INDEX:Object = {MIN: 1, MAX: 4};
		
		public function ParadiseMap()
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE, this.added, false, 0, true);
			this.addEventListener(Event.REMOVED_FROM_STAGE, this.removed, false, 0, true);
			this.tabChildren = false;
			this.tabEnabled = false;
			this.init();
		}
		
		public var s1_1:MovieClip;
		public var s1_2:MovieClip;
		public var s1_3:MovieClip;
		public var s2_1:MovieClip;
		public var s2_2:MovieClip;
		public var s2_3:MovieClip;
		public var s3_1:MovieClip;
		public var s3_2:MovieClip;
		public var s3_3:MovieClip;
		public var sssl:MovieClip;
		public var moonmc:MovieClip;
		public var btnnmg:MovieClip;
		public var dsgbtn:MovieClip;
		public var kls:SimpleButton;
		public var llbt:SimpleButton;
		public var s4_1:MovieClip;
		public var s4_2:MovieClip;
		public var s4_3:MovieClip;
		public var hdbtn:MovieClip;
		public var hyChallenge:MovieClip;
		public var stzmc:MovieClip;
		public var sssd:SimpleButton;
		public var sgzz:SimpleButton;
		
		private function init():void
		{
			for (var stageNum:int = MAP_INDEX.MIN; stageNum <= MAP_INDEX.MAX; stageNum++)
			{
				levelNum = 0;
				for (var levelNum:int = 1; levelNum <= 3; levelNum++)
				{
					if (this["s" + stageNum + "_" + levelNum] != null)
					{
						this["s" + stageNum + "_" + levelNum].gotoAndStop(1);
						this["s" + stageNum + "_" + levelNum].buttonMode = true;
					}
				}
			}
			this.moonmc.buttonMode = true;
			this.stzmc.buttonMode = true;
			this.hyChallenge.buttonMode = true;
			this.btnnmg.buttonMode = true;
			this.sssl.buttonMode = true;
			this.dsgbtn.buttonMode = true;
			this.hdbtn.buttonMode = true;
		}
		
		private function added(param1:Event):void
		{
			var bStage:int = Config.getIns().userData.maxStage;
			var bLevel:int;
			if (bStage > MAP_INDEX.MAX)
			{
				bStage = MAP_INDEX.MAX;
			}
			for (var i:int = MAP_INDEX.MIN; i <= bStage; i++)
			{
				var j:int;
				if (i < bStage)
				{
					bLevel = 3;
				}
				else
				{
					bLevel = Config.getIns().userData.maxLevel;
				}
				for (j = 1; j <= bLevel; j++)
				{
					var str1:String = "s" + i + "_" + j;
					if (this[str1] != null)
					{
						this[str1].addEventListener(MouseEvent.CLICK, this.onSelected);
						this[str1].addEventListener(MouseEvent.ROLL_OVER, this.mOver);
						this[str1].addEventListener(MouseEvent.ROLL_OUT, this.mOut);
					}
				}
			}
			var str2:String = "s" + Config.getIns().userData.maxStage + "_" + Config.getIns().userData.maxLevel;
			if (this.hasOwnProperty(str2) && this[str2] != null)
			{
				this[str2].gotoAndStop(3);
			}
			this.moonmc.addEventListener(MouseEvent.CLICK, this.moonClick);
			this.moonmc.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.moonmc.addEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.sssd.addEventListener(MouseEvent.CLICK, this.shopClick);
			this.stzmc.addEventListener(MouseEvent.CLICK, this.stzClick);
			this.stzmc.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.stzmc.addEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.hyChallenge.addEventListener(MouseEvent.CLICK, this.hyPlace);
			this.hyChallenge.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.hyChallenge.addEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.btnnmg.addEventListener(MouseEvent.CLICK, this.nmgClick);
			this.btnnmg.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.sssl.addEventListener(MouseEvent.CLICK, this.ssslClick);
			this.sssl.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.sssl.addEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.dsgbtn.addEventListener(MouseEvent.CLICK, this.dsgClick);
			this.dsgbtn.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.dsgbtn.addEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.btnnmg.addEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.sgzz.addEventListener(MouseEvent.CLICK, this.tozm4level);
			this.kls.addEventListener(MouseEvent.CLICK, this.inToKunLunMountains);
			this.llbt.addEventListener(MouseEvent.CLICK, this.inToLingLongTower);
			this.hdbtn.addEventListener(MouseEvent.CLICK, this.newWorldClick);
			this.hdbtn.addEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.hdbtn.addEventListener(MouseEvent.ROLL_OUT, this.mOut);
			var menu:MapMenu = this.getChildByName("showedMapMenu") as MapMenu;
			if (menu != null)
			{
				this.removeChild(menu);
			}
			menu = new MapMenu();
			menu.x = menu.y = 0;
			menu.name = "showedMapMenu";
			this.addChild(menu);
		}
		
		private function removed(param1:Event):void
		{
			for (var i:int = MAP_INDEX.MIN; i <= MAP_INDEX.MAX; i++)
			{
				for (var j:int = 0; j <= 3; j++)
				{
					var str1:String = "s" + i + "_" + j;
					if (this.hasOwnProperty(str1) && this[str1] != null)
					{
						this[str1].removeEventListener(MouseEvent.CLICK, this.onSelected);
						this[str1].removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
						this[str1].removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
					}
				}
			}
			this.hyChallenge.removeEventListener(MouseEvent.CLICK, this.hyPlace);
			this.hyChallenge.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.hyChallenge.removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.sssd.removeEventListener(MouseEvent.CLICK, this.shopClick);
			this.sssd.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.sssd.removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.stzmc.removeEventListener(MouseEvent.CLICK, this.stzClick);
			this.stzmc.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.stzmc.removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.moonmc.removeEventListener(MouseEvent.CLICK, this.moonClick);
			this.moonmc.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.moonmc.removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.btnnmg.removeEventListener(MouseEvent.CLICK, this.nmgClick);
			this.moonmc.removeEventListener(MouseEvent.CLICK, this.moonClick);
			this.btnnmg.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.btnnmg.removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.kls.removeEventListener(MouseEvent.CLICK, this.inToKunLunMountains);
			this.llbt.removeEventListener(MouseEvent.CLICK, this.inToLingLongTower);
			this.sssl.removeEventListener(MouseEvent.CLICK, this.ssslClick);
			this.sssl.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.sssl.removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
			this.hdbtn.removeEventListener(MouseEvent.CLICK, this.newWorldClick);
			this.hdbtn.removeEventListener(MouseEvent.ROLL_OVER, this.mOver);
			this.hdbtn.removeEventListener(MouseEvent.ROLL_OUT, this.mOut);
		}
		
		private function hyPlace(param1:MouseEvent):void
		{
			this.gc.curStage = 53;
			this.gc.curLevel = 1;
			
		}
		
		private function shopClick(param1:MouseEvent):void
		{
			if (this.gc.playerData.level < 30)
			{
				NotificationManager.alert("玩家的等级必须都大于30级才可以进入");
				return;
			}
//			new MythShopInter();
		}
		
		private function stzClick(param1:MouseEvent):void
		{
			if (this.gc.playerData.level < 30)
			{
				NotificationManager.alert("玩家的等级必须都大于30级才可以进入");
				return;
			}
			new ThreeBrothersInter();
		}
		
		private function newWorldClick(_loc1_:MouseEvent):void
		{
			if (this.gc.playerData.level < 40)
			{
				NotificationManager.alert("玩家的等级必须都大于40级才可以进入");
				return;
			}
			new Trans1Inter();
		}
		
		private function mOver(param1:MouseEvent):void
		{
			param1.currentTarget.gotoAndStop(3);
		}
		
		private function mOut(param1:MouseEvent):void
		{
			var str1:String = param1.currentTarget.name;
			if (!this.hasOwnProperty(str1) || this[str1] == null)
			{
				return;
			}
			if (str1 == "s" + Config.getIns().userData.maxStage + "_" + Config.getIns().userData.maxLevel)
			{
				this[str1].gotoAndStop(3);
			}
			else
			{
				this[str1].gotoAndStop(1);
			}
		}
		
		private function onSelected(param1:MouseEvent):void
		{
			var str1:String = param1.currentTarget.name.replace("s", "");
			Config.getIns().curStage = int(str1.split("_")[0]);
			Config.getIns().curLevel = int(str1.split("_")[1]);
			
		}
		
		private function inToKunLunMountains(param1:MouseEvent):void
		{
			this.gc.curStage = 0;
			this.gc.curLevel = 1;
			
		}
		
		private function moonClick(param1:MouseEvent):void
		{
			this.gc.curStage = 46;
			this.gc.curLevel = 1;
			
		}
		
		private function inToLingLongTower(param1:MouseEvent):void
		{
			if (this.gc.userData.maxStage < 4)
			{
				NotificationManager.alert("请先通过凌霄宝殿的考验！");
				return;
			}
			this.gc.curStage = 8;
			this.gc.curLevel = 1;
			
		}
		
		private function nmgClick(param1:MouseEvent):void
		{
			if (this.gc.userData.maxStage < 3 || this.gc.userData.maxStage == 3 && this.gc.userData.maxLevel < 3)
			{
				NotificationManager.alert("请先通过朝会殿的考验！");
				return;
			}
			this.gc.curStage = 4;
			this.gc.curLevel = 1;
			
		}
		
		private function ssslClick(param1:MouseEvent):void
		{
			if (this.gc.userData.maxStage < 4)
			{
				NotificationManager.alert("请先通过凌霄宝殿的考验！");
				return;
			}
			this.gc.curStage = 9;
			this.gc.curLevel = 1;
			
		}
		
		private function tozm4level(param1:MouseEvent):void
		{
			new FutureBoatInter();
		}
		
		private function dsgClick(param1:MouseEvent):void
		{
			if (this.gc.playerData.level < 40)
			{
				NotificationManager.alert("玩家的等级必须都大于40级才可以进入");
				return;
			}
			this.gc.curStage = 12;
			this.gc.curLevel = 1;
			
		}
	}
}
